﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;

namespace Jarvis.Sensors
{
    class USBSensor : Sensor
    {
        public USBSensor()
            : base(1000)
        {
            this.name = "USB Devices";
        }

        public override void Sense(Object stateInfo)
        {
            List<object> devices = new List<object>();

            ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", 
                "SELECT * FROM Win32_USBControllerDevice");

            foreach (ManagementObject queryobj in searcher.Get())
            {
                ManagementObject mbo = new ManagementObject(queryobj["Dependent"].ToString());
                string device = "";
                foreach (PropertyData prop in mbo.Properties)
                {
                    if (prop.Name == "Caption")
                        device += prop.Value.ToString();
                }
                devices.Add(device);
            }

            this.log(devices);
        }
    }
}
